<?php
/**
 * 控制器公共方法
 * publiccontroller.php
 * Create on 2015-04-03 16:52:28
 * Create by yuebin
 */
namespace haibao\cms\business\control;
use haibao\frame\data\query\Condition;
use haibao\cms\model\filter\Article as ArticleFilter;
use haibao\cms\model\filter\ArticleTag as ArticleTagFilter;
use haibao\cms\model\filter\ArticleProperty as ArticlePropertyFilter;
use haibao\cms\model\filter\imagecollective\ImageCollective as ImageCollectiveFilter;
use haibao\cms\model\filter\imagecollective\ImageCollectiveTag as ImageCollectiveTagFilter;
use haibao\cms\model\filter\imagecollective\ImageCollectivePro as ImageCollectiveProFilter;
use haibao\cms\model\filter\imagecollective\ImageCollectiveProperty as ImageCollectivePropertyFilter;
use haibao\cms\model\filter\imagecollective\ImageCollectiveArticle as ImageCollArticleFilter;
use haibao\cms\model\filter\ImageLibrary as ImageLibraryFilter;
use haibao\cms\business\Tag as TagBusiness;
use haibao\cms\data\control\PublicController as PublicControllerData;
use haibao\cms\model\filter\FeaturePublish as FeaturePublishFilter;
use haibao\cms\model\data\FeaturePublish as FeatureModel;
use haibao\cms\model\filter\Calendar as CalendarFilter;
use haibao\cms\model\filter\CalendarPicPoint as CalendarPicPointFilter;
use haibao\cms\model\filter\Product as ProductFilter;
use haibao\cms\model\filter\ProductModel as ProductModelFilter;
use haibao\cms\model\filter\Celebrity as CelebrityFilter;
use haibao\cms\model\filter\CelebrityImage as CelebrityImageFilter;
use haibao\cms\model\filter\CelebrityInfo as CelebrityInfoFilter;
use haibao\cms\model\filter\CelebrityRiseCount as CelebrityRiseCountFilter;
use haibao\cms\model\filter\TryProduct as TryProductFilter;
use haibao\cms\model\filter\Video as VideoFilter;
use haibao\cms\model\filter\VideoCategory as VideoCategoryFilter;
use haibao\frame\data\query\Pager;
use \haibao\www\model\filter\ZtSpecial as ZtSpecialFilter;
use \haibao\www\model\data\ZtSpecial as ZtSpecialData;
use haibao\cms\model\filter\ArticleImage;
use \haibao\cms\model\filter\CalendarProduct as CalendarProductFilter;
use haibao\cms\business\FeaturePublish;

class PublicController extends \haibao\cms\business\Base{

    private static $pager;
    
	/**
	 * 根据频道获取频道流量最高的资讯或图集的主标签
	 * @param : $topTagId 顶级标签ID
	 * @param : $tagUrl 标签Url
	 * @param : $isColl 是否需要图注标签
	 */
	public static function getKeyWordsByChannel($topTagId,$isColl = true){
		
		$finalArr = array();
		$articleKeyWords = self::getArticleKeyWords($topTagId);
		foreach($articleKeyWords as $key=>$val){
			$finalArr[$key] = $val;
		}
		if($isColl){
			$collKeyWords = self::getImageCollKeyWords($topTagId);
			foreach($collKeyWords as $key=>$val){
				$finalArr[$key] = $val;
			}
		}
		// TODO : 对标签进行排重
		$finalArr = array_unique($finalArr);
		if(count($finalArr) > 5) $finalArr =array_slice($finalArr, 0,5);
		// 获取标签信息
		$tagInfo = TagBusiness::getTagsById($finalArr);
		$topTags = \haibao\cms\business\control\Base::getTopTags();
	
		$tagArr = array();
		foreach($tagInfo as $key=>$info){
			
			$info['Url'] = \haibao\cms\business\control\Base::getTagUrl($info['Url'],$info['TagType'],$info['TopId'],$info['Id']);
			array_push($tagArr,$info);
		}
		return $tagArr;
		
	}
	/**
	 * 根据频道获取频道流量最高的资讯主标签
	 * @param : $topTagId 顶级标签ID
	 */
	public static function getArticleKeyWords($topTagId){
		
		// TODO : 获取一周时间范围内该频道流量最高的资讯的主标签
		$articleFilter = new ArticleFilter();
		$articleTagFilter = new ArticleTagFilter();
		$articlePropertyFilter = new ArticlePropertyFilter();
		$articleFilter->select(
			array(
				ArticleFilter::CONDITION_FIELD_NAME_ID
			)
		);
		$articleTagFilter->select(
			array(
				ArticleTagFilter::CONDITION_FIELD_NAME_TAG_ID
			)
		);
		$articlePropertyFilter->select(
			array(
				ArticlePropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM
			)
		);
	
		$articleFilter->order(ArticlePropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM,false,$articlePropertyFilter);
		$articleFilter->limit(0,5);
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,Condition::CONDITION_BETWEEN,array(date('Y-m-d',strtotime('-1 weeks')),date('Y-m-d')));
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\Article::PUBLISHED_YES);
		if(is_array($topTagId)){
			$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,Condition::CONDITION_IN,$topTagId);
		}else{
			$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_PARENT_ID,Condition::CONDITION_EQUAL,$topTagId);
		}
		$articleTagFilter->where(ArticleTagFilter::CONDITION_FIELD_NAME_IS_PRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleTag::PRIMAIY_IS);
		$articlePropertyFilter->where(ArticlePropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM,Condition::CONDITION_NOTEQUAL,0);
		
		
		$articleFilter->leftJoin($articleTagFilter,null,ArticleFilter::CONDITION_FIELD_NAME_ID,ArticleTagFilter::CONDITION_FIELD_NAME_ARTICLE_ID,ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_TAG,false);
		$articleFilter->leftJoin($articlePropertyFilter,null,ArticleFilter::CONDITION_FIELD_NAME_ID,ArticlePropertyFilter::CONDITION_FIELD_NAME_ARTICLE_ID,ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_PROPERTY,false);
		
		$articles = \haibao\cms\business\Article::getArticleList($articleFilter);
		$tempArr = array();
			foreach($articles as $article){
			$tempArr[$article->ArticleProperty->ClickNum] = $article->ArticleTag->TagId;
		}
		return $tempArr;
	}
	/**
	 * 根据频道获取频道流量最高的资讯主标签
	 * @param : $topTagId 顶级标签ID
	 */
	public static function getImageCollKeyWords($topTagId){

		$imageCollectiveFilter = new ImageCollectiveFilter();
		$imageCollectiveFilter->select(array(
				ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,
		));
		
		$imageCollectiveTagFilter = new ImageCollectiveTagFilter();
		$imageCollectiveTagFilter->select(array(
				ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_ID,
		));
		$imageCollPropertyFilter = new ImageCollectivePropertyFilter();
		$imageCollPropertyFilter->select(array(
				ImageCollectivePropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM,
		));
		$imageCollectiveFilter->order(ImageCollectivePropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM,false,$imageCollPropertyFilter);

		
		$imageCollectiveFilter->limit(0,5);
		//$imageCollectiveFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_CREATE_TIME,Condition::CONDITION_BETWEEN,array(date('Y-m-d',strtotime('-1 weeks')),date('Y-m-d')));
		
		if(is_array($topTagId)){
			$imageCollectiveTagFilter->where(ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,Condition::CONDITION_IN,$topTagId);
		}else{
			$imageCollectiveTagFilter->where(ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,Condition::CONDITION_EQUAL,$topTagId);
		}
		
		$imageCollectiveTagFilter->where(ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
		$imageCollPropertyFilter->where(ImageCollectivePropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM,Condition::CONDITION_NOTEQUAL,0);
		
		
		$imageCollectiveFilter->leftJoin($imageCollectiveTagFilter,null,ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_TAG,false);
		$imageCollectiveFilter->leftJoin($imageCollPropertyFilter,null,ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,ImageCollectivePropertyFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID,ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PRO,false);

		$data = new \haibao\cms\data\imagecollective\ImageCollective();
		$imageColls = $data->getAll($imageCollectiveFilter);
		$tempArr = array();
		foreach($imageColls as $coll){
			$tempArr[$coll->ImageCollectivePro->ClickNum] = $coll->ImageCollectiveTag->TagId;
		}
		return $tempArr;
	}
	
	/**
	 * 根据频道获取频道下最新的2个专题
	 * @param : $classId 专题类别  （1潮流，2美妆，3明星,4时装周，5品牌）  如果改频道下没有，则查询时装频道
	 * @param : $limit 返回个数，默认2
	 */
	public static function getNewFeatureByChannel($classId=FeatureModel::CLASS_FASHION_WEEK,$limit=2,$isPage=false,$page=1,$serialId = null,$columnId = null){
	    return \haibao\cms\business\control\FeatureController::getNewFeatureByChannelForIndex($classId,$limit,$isPage,$page,$serialId,$columnId);
	}
	
	
	/**
	 * 根据频道获取频道下最新的2个专题
	 * @param : $classId 专题类别  （1潮流，2美妆，3明星,4时装周，5品牌）  如果改频道下没有，则查询时装频道
	 * @param : $limit 返回个数，默认2
	 */
	public static function getFeatureByChannel($classId=FeatureModel::CLASS_FASHION_WEEK,$limit=2,$isPage=false,$page=1,$serialId = null){
	    return \haibao\cms\business\control\FeatureController::getFeatureByChannel($classId,$limit,$isPage,$page,$serialId);
	}
	
	/**
	 * 根据频道获取频道下最新的2个专题     （老库）
	 * @param : $classId 专题类别  （1潮流，2美妆，3明星,4时装周，5品牌）  如果改频道下没有，则查询时装频道
	 * @param : $limit 返回个数，默认2
	 */
	public static function getFeatureByClass($classId=FeatureModel::CLASS_FASHION_WEEK,$limit=2){
	    $ztSpecialFilter = new ZtSpecialFilter();
	    $ztSpecialFilter->select(array(
	        ZtSpecialFilter::CONDITION_FIELD_NAME_ID,
	        ZtSpecialFilter::CONDITION_FIELD_NAME_DESCRIPTION,
	        ZtSpecialFilter::CONDITION_FIELD_NAME_PIC,
	        ZtSpecialFilter::CONDITION_FIELD_NAME_TITLE,
	        ZtSpecialFilter::CONDITION_FIELD_NAME_URL,
	        ZtSpecialFilter::CONDITION_FIELD_NAME_LIST_DATE
	    ));
	    $ztSpecialFilter->order(ZtSpecialFilter::CONDITION_FIELD_NAME_LIST_DATE,false);
	    $ztSpecialFilter->where(ZtSpecialFilter::CONDITION_FIELD_NAME_LIST_SHOW, Condition::CONDITION_EQUAL, ZtSpecialData::LIST_SHOW_ENABLE);
	    $ztSpecialFilter->where(ZtSpecialFilter::CONDITION_FIELD_NAME_TAG, Condition::CONDITION_EQUAL, $classId);
	    $ztSpecialFilter->limit($limit);
	    
	    $result = \haibao\www\business\ZtSpecial::getFeatureList($ztSpecialFilter);
	    return $result;
	}
	
	public static function getMobileFeatureList($page,$limit=4){
		return \haibao\cms\business\control\FeatureController::getMobileFeatureList($page,$limit);
	}
	
	/**
	 * 通过栏目ID获取专题
	 */
	public static function getFeaturelist($columnId=0,$limit=3,$page=1,$isKillBrand=true){
	   return \haibao\cms\business\control\FeatureController::getFeaturelist($columnId,$limit,$page,$isKillBrand);
	}
	
	
	public static function getserialInfoById($serialId,$limit=1){
	   return \haibao\cms\business\control\FeatureController::getserialInfoById($serialId,$limit);
	}
	
	public static function getFeatureByCId($columnId=0,$limit=3,$page=1,$featureOldIds = array()){
	    $ztSpecialFilter = new ZtSpecialFilter();
	    $ztSpecialFilter->select(array(
	        ZtSpecialFilter::CONDITION_FIELD_NAME_ID,
	        ZtSpecialFilter::CONDITION_FIELD_NAME_DESCRIPTION,
	        ZtSpecialFilter::CONDITION_FIELD_NAME_PIC,
	        ZtSpecialFilter::CONDITION_FIELD_NAME_TITLE,
	        ZtSpecialFilter::CONDITION_FIELD_NAME_URL,
	        ZtSpecialFilter::CONDITION_FIELD_NAME_LIST_DATE
	    ));
	    $ztSpecialFilter->order(ZtSpecialFilter::CONDITION_FIELD_NAME_LIST_DATE,false);
	    
	    if($featureOldIds){

	    	$ztSpecialFilter->where(ZtSpecialFilter::CONDITION_FIELD_NAME_ID, Condition::CONDITION_NOTIN, $featureOldIds);
	    }
	    $ztSpecialFilter->where(ZtSpecialFilter::CONDITION_FIELD_NAME_LIST_SHOW, Condition::CONDITION_EQUAL, ZtSpecialData::LIST_SHOW_ENABLE);
	    if($columnId != -1){
	        $ztSpecialFilter->where(ZtSpecialFilter::CONDITION_FIELD_NAME_ZT_VIDEO_CATE, Condition::CONDITION_EQUAL, $columnId);
	    }
	    $ztSpecialFilter->setPager(new Pager($limit,$page));
	
	    $result = \haibao\www\business\ZtSpecial::getFeatureList($ztSpecialFilter);
	    self::$pager = $ztSpecialFilter->getPager();
	    return $result;
	
	}
	
	public static function getVideolist($cId=0,$limit=3,$page=1,$notVideoId=0){
	    $result = self::getVideoByCateId($cId,$limit,$page,$notVideoId);
	    return array($result,self::$pager);
	}
	
	public static function getVideoByCateId($cId,$limit=3,$page=1,$notVideoId=0){
	    $videoFilter = new VideoFilter();
	    $videoFilter->select(array(
	        VideoFilter::CONDITION_FIELD_NAME_ID,
	        VideoFilter::CONDITION_FIELD_NAME_TITLE,
	        VideoFilter::CONDITION_FIELD_NAME_VIDEOURL,
	        VideoFilter::CONDITION_FIELD_NAME_URLH5,
	        VideoFilter::CONDITION_FIELD_NAME_LASTMODIFYUSER,
	        VideoFilter::CONDITION_FIELD_NAME_LASTMODIFYTIME,
	        VideoFilter::CONDITION_FIELD_NAME_PUBLISHDATE,
	        VideoFilter::CONDITION_FIELD_NAME_CATEGORYID,
	        VideoFilter::CONDITION_FIELD_NAME_PUBLISHED
	    ));
	    $videoFilter->order(VideoFilter::CONDITION_FIELD_NAME_ID,false);
	    $videoFilter->where(VideoFilter::CONDITION_FIELD_NAME_STATUS, Condition::CONDITION_EQUAL,\haibao\cms\model\data\Video::STATUS_ENABLE);
	    $videoFilter->where(VideoFilter::CONDITION_FIELD_NAME_PUBLISHED, Condition::CONDITION_EQUAL,\haibao\cms\model\data\Video::PUBLISHED_OK);
	    if($cId == 0){
	        $videoCategoryFilter = new VideoCategoryFilter();
	        $videoCategoryFilter->select(array(
	            VideoCategoryFilter::CONDITION_FIELD_NAME_ID,
	            VideoCategoryFilter::CONDITION_FIELD_NAME_STATUS,
	            VideoCategoryFilter::CONDITION_FIELD_NAME_PARENTID
	        ));
	        $videoFilter->leftJoin($videoCategoryFilter,null,VideoFilter::CONDITION_FIELD_NAME_CATEGORYID,VideoCategoryFilter::CONDITION_FIELD_NAME_ID,false);
	        //$videoCategoryFilter->where(VideoCategoryFilter::CONDITION_FIELD_NAME_PARENTID, Condition::CONDITION_NOTEQUAL, 2);
	    }else{
	        if($cId != -1){
	            $videoFilter->where(VideoFilter::CONDITION_FIELD_NAME_CATEGORYID, Condition::CONDITION_EQUAL, $cId);
	        }
	    }
	    if($notVideoId){
	    	$videoFilter->where(VideoFilter::CONDITION_FIELD_NAME_ID, Condition::CONDITION_NOTEQUAL,$notVideoId);
	    }
	    $imageLibraryFilter = new ImageLibraryFilter();
	    $imageLibraryFilter->select(array(
	        ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
	    ));
	    $videoFilter->leftJoin($imageLibraryFilter,$videoFilter,VideoFilter::CONDITION_FIELD_NAME_PICID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,VideoFilter::CONDITION_FIELD_NAME_PIC_URL,false);
	    
	    $videoFileFilter = new \haibao\cms\model\filter\VideoFile();
	    $videoFileFilter->select(array(
	        \haibao\cms\model\filter\VideoFile::CONDITION_FIELD_NAME_ID,
	        \haibao\cms\model\filter\VideoFile::CONDITION_FIELD_NAME_VIDEOID,
	        \haibao\cms\model\filter\VideoFile::CONDITION_FIELD_NAME_FILEPATH,
	        \haibao\cms\model\filter\VideoFile::CONDITION_FIELD_NAME_STATUS,
	    ));
	    $videoFilter->leftJoin($videoFileFilter,$videoFilter,VideoFilter::CONDITION_FIELD_NAME_ID,\haibao\cms\model\filter\VideoFile::CONDITION_FIELD_NAME_VIDEOID,VideoFilter::CONDITION_FIELD_NAME_VIDEOFILE,false);
	    
	    $videoFilter->setPager(new Pager($limit,$page));
	    $data = new \haibao\cms\data\Video();
	    $result = $data->getAll($videoFilter);
	    self::$pager = $videoFilter->getPager();
	    return $result;
	}
	
	public static function getCoverVideo(){
		$videoFilter = new VideoFilter();
		$videoFilter->select(array(
				VideoFilter::CONDITION_FIELD_NAME_ID,
				VideoFilter::CONDITION_FIELD_NAME_TITLE,
				VideoFilter::CONDITION_FIELD_NAME_VIDEOURL,
				VideoFilter::CONDITION_FIELD_NAME_URLH5,
				VideoFilter::CONDITION_FIELD_NAME_LASTMODIFYUSER,
				VideoFilter::CONDITION_FIELD_NAME_LASTMODIFYTIME,
				VideoFilter::CONDITION_FIELD_NAME_PUBLISHDATE,
				VideoFilter::CONDITION_FIELD_NAME_CATEGORYID,
				VideoFilter::CONDITION_FIELD_NAME_PUBLISHED,
				VideoFilter::CONDITION_FIELD_NAME_SURFACE_PICID
		));
		$videoFilter->order(VideoFilter::CONDITION_FIELD_NAME_ID,false);
		$videoFilter->where(VideoFilter::CONDITION_FIELD_NAME_STATUS, Condition::CONDITION_EQUAL,\haibao\cms\model\data\Video::STATUS_ENABLE);
		$videoFilter->where(VideoFilter::CONDITION_FIELD_NAME_PUBLISHED, Condition::CONDITION_EQUAL, 1);
		$videoFilter->where(VideoFilter::CONDITION_FIELD_NAME_SURFACE_PICID, Condition::CONDITION_GREATER, 0);
		$imageLibraryFilter = new ImageLibraryFilter();
		$imageLibraryFilter->select(array(
				ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
		));
		$videoFilter->leftJoin($imageLibraryFilter,null,VideoFilter::CONDITION_FIELD_NAME_SURFACE_PICID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,VideoFilter::CONDITION_FIELD_NAME_PIC_URL,false);
		$data = new \haibao\cms\data\Video();
		$result = $data->getOne($videoFilter);
		return $result;
	}
	
	public static function getImageCollectiveByChannel($tagId,$proLevel=1,$date=1,&$imageCollectiveInfo = null){
	    
		$imageCollectiveFilter = new ImageCollectiveFilter();
	    $imageCollectiveFilter->select(array(
	        ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,
	        ImageCollectiveFilter::CONDITION_FIELD_NAME_TITLE
	         
	    ));
	     
	    $imageCollectiveTagFilter = new ImageCollectiveTagFilter();
	    $imageCollectiveTagFilter->select(array(
	        ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_ID,
	    ));

	    $imageCollProperyFilter = new ImageCollectivePropertyFilter();
	    $imageCollProperyFilter->select(array(
	    		ImageCollectivePropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM
	    ));
	    
	    $imageCollectiveFilter->order(ImageCollectivePropertyFilter::CONDITION_FIELD_NAME_CLICK_NUM,false,$imageCollProperyFilter);
	    $imageCollectiveFilter->limit(1);
	    
	    $imageCollectiveFilter->leftJoin($imageCollectiveTagFilter,null,ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_TAG,false);
	    $imageCollectiveFilter->leftJoin($imageCollProperyFilter,null,ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,ImageCollectivePropertyFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID,ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PRO,false);
	    if($date == 1){
	   		$imageCollectiveFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,Condition::CONDITION_BETWEEN,array(date('Y-m-d',strtotime('-1 weeks')),date('Y-m-d',strtotime('+1 days'))));
	    }elseif($date == 2){
	    	$imageCollectiveFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,Condition::CONDITION_BETWEEN,array(date('Y-m-d',strtotime('-1 month')),date('Y-m-d',strtotime('+1 days'))));
	    }
	    $imageCollectiveFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollective::STATUS_ENABLE);
	    $imageCollectiveFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,5);
	    $imageCollectiveFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollective::STATUS_YES_PUBLISH);
	    $imageCollectiveTagFilter->where(ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);

	    if(is_array($tagId)){
	        $imageCollectiveTagFilter->where(ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,Condition::CONDITION_IN,$tagId);
	    }else{
	        $imageCollectiveTagFilter->where(ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID,Condition::CONDITION_EQUAL,$tagId);
	    }
	    
	     
	    $data = new \haibao\cms\data\imagecollective\ImageCollective();
	    $imageCollective = $data->getOne($imageCollectiveFilter);
	    if(empty($imageCollective)){
	    	if($date==1){
	    		self::getImageCollectiveByChannel($tagId,$proLevel,2,$imageCollectiveInfo);
	    	}
	    }else{
	        $imageCollectiveInfo = self::getImageCollectivePro($imageCollective,$proLevel);
	    }
	    
		return $imageCollectiveInfo;
	}
	
	/**
	 * 获取频道下最新的一条图集信息
	 * @param : Int $tagId 频道标签Id
	 * @param : Int $proLevel 图集等级
	 */
	public static function getImageCollectivePro($imageCollective,$proLevel){
	    $collId = $imageCollective->Id;
	    $imageCollProFilter = new ImageCollectiveProFilter();
		$imageCollProFilter->select(
				array(
					ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID,
					ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_IMAGE_TYPE,
					ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_ID,
				)
		);
		$imageLibraryFilter = new ImageLibraryFilter();
		$imageLibraryFilter->select(array(
				ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
		));
		$proImageLevel = array($proLevel);
		array_push($proImageLevel,\haibao\cms\model\data\imagecollective\ImageCollectivePro::IMAGE_TYPE_ZERO);
		$imageCollProFilter->where(ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_IMAGE_TYPE,Condition::CONDITION_IN,$proImageLevel);
		$imageCollProFilter->where(ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID,Condition::CONDITION_EQUAL,$collId);
		$imageCollProFilter->leftJoin($imageLibraryFilter,null,ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_ID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_FILENAME,false);
        
		$data = new \haibao\cms\data\imagecollective\ImageCollective();
		$collProImages = $data->getAll($imageCollProFilter);
		$proImageArr = array('title'=>$imageCollective->Title,'id'=>$collId);
		foreach($collProImages as $proImage){
		        $proImageArr[$proImage->ImageType] = $proImage->FileName->Filename;
		}
	    return $proImageArr;
	}
	
	/*这个星期的星期一
	 *@param : String $timestamp 某个星期的某一个时间戳，默认为当前时间
	 *@param : Boolure is_return_timestamp 是否返回时间戳，否则返回时间格式
	 */
	public static function thisMonday($timestamp=0,$is_return_timestamp=true){
		static $cache ;
		$id = $timestamp.$is_return_timestamp;
		if(!isset($cache[$id])){
			if(!$timestamp) $timestamp = time();
			$monday_date = date('Y-m-d', $timestamp-86400*date('w',$timestamp)+(date('w',$timestamp)>0?86400:-518400));
			if($is_return_timestamp){
				$cache[$id] = strtotime($monday_date);
			}else{
				$cache[$id] = $monday_date;
			}
		}
		return $cache[$id];
	}
	
	/*这个星期的星期日
	 *@param : String $timestamp 某个星期的某一个时间戳，默认为当前时间
	 *@param : Boolure is_return_timestamp 是否返回时间戳，否则返回时间格式
	 */
	public static function thisSunday($timestamp=0,$is_return_timestamp=true){
		static $cache ;
		$id = $timestamp.$is_return_timestamp;
		if(!isset($cache[$id])){
			if(!$timestamp) $timestamp = time();
			$sunday = self::thisMonday($timestamp) + /*6*86400*/518400;
			if($is_return_timestamp){
				$cache[$id] = $sunday;
			}else{
				$cache[$id] = date('Y-m-d',$sunday);
			}
		}
		return $cache[$id];
	}
	
	/**
	 * 获取频道下的最新博主资讯
	 * @param : Int $cateId 分类ID
	 * @param : Array $delBlogIds 过滤的博主信息
	 * @param : Int $limit 数据限制
	 */
	public static function getBlogArticleInfoByCateId($cateId,$delBlogIds = array(),$limit = 3){
	
		$publicControllerData = new PublicControllerData();
		return $publicControllerData->getBlogArticleInfoByCateId($cateId,$delBlogIds,$limit);
	}
	
	/**
	 * 根据博主ID获取博主资讯
	 */
	public static function getBlogListByBlogId($blogIds){

		if(!$blogIds) return false;
		$publicControllerData = new PublicControllerData();
		return $publicControllerData->getBlogListByBlogId($blogIds);
	}
	
	public static function geteBlogIdByUid($uids){
		if(!$uids) return false;
		$publicControllerData = new PublicControllerData();
		return $publicControllerData->getBlogIdByUid($uids);
	}
	/**
	 * 获取论坛板块资讯
	 */
	public static function getThreadData($param = array()){

		$threadDataList = array();
		$publicControllerData = new PublicControllerData();
		$param['width'] = 0;
		$param['height'] = 0;
		$param['dateline'] = 0;
		$param['type'] = 2;
		$param['limit'] = 3;
		$param['groupId'] = 12;
		$threadDataList = array_merge($threadDataList,$publicControllerData->getThreadData($param));
		$param['groupId'] = 23;
		$threadDataList = array_merge($threadDataList,$publicControllerData->getThreadData($param));
		$param['limit'] = 2;
		$param['groupId'] = 18496;
		$threadDataList = array_merge($threadDataList,$publicControllerData->getThreadData($param));
		return $threadDataList;
	}
	/**
	 * 获取标签信息
	 * @param ： Array $tagIds
	 */
	public static function getTagInfoById($tagIds,$source = ''){
		$tagIds = array_unique($tagIds);
		// 获取标签信息
		$tagList = TagBusiness::getTagsById($tagIds);
		$tagArr = array();
		$topTags = \haibao\cms\business\control\Base::getTopTags();
		foreach($tagIds as $tag){
			
			if(isset($tagList[$tag])){
				$tagInfo = $tagList[$tag];
				$tagArr[$tag]['Url'] = \haibao\cms\business\control\Base::getTagUrl($tagInfo['Url'],$tagInfo['TagType'],$tagInfo['TopId'],$tag);
				$tagArr[$tag]['TagName'] = $tagInfo['TagName'];
				$tagArr[$tag]['TagType'] = $tagInfo['TagType'];
				$tagArr[$tag]['ParentId'] = $tagInfo['ParentId'];
			}else{
				
				$tagArr[$tag]['Url'] = '';
				$tagArr[$tag]['TagName'] = '暂无标签';
				$tagArr[$tag]['TagType'] = '';
				$tagArr[$tag]['ParentId'] = '';
			}
		}
		return $tagArr;
	}
	
	public static function getStarCenterUrlByTagId($tagIds){
	    $tagList = TagBusiness::getTagsById($tagIds);
	    $starUrlArr = array();
	    //$topTags = \haibao\cms\business\control\Base::getTopTags();
	    $starsHost = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_STARS);
	    
	    foreach($tagList as $key=>$tag){
	        $starUrlArr[$key] = $starsHost.$tag['Url'];
	    }
	    return $starUrlArr;
	}
	
	public static function getLowerChannelById($pid){
	    $publicControllerData = new PublicControllerData();
	    return $publicControllerData->getLowerChannelById($pid);
	}
	
	public static function getLowerChannelByParentName($pname){
	    $publicControllerData = new PublicControllerData();
	    return $publicControllerData->getLowerChannelByParentName($pname);
	}
	
	public static function getArticleIdByStarType($limit=3,$isLike=1){
	    $publicControllerData = new PublicControllerData();
	    $arrIds = $publicControllerData->getArticleIdByStarType($limit,$isLike);
	    $arrIds = array_unique($arrIds);
	    $arrTagId = array_keys($arrIds);
	    if(count($arrIds) > 3){
	        $arrAids = array_slice($arrIds, 0, 3);
	        $arrTagId = array_slice($arrTagId, 0, 3);
	    } else {
	    	$arrAids = $arrIds;
	    }
	    $articleController =new \haibao\cms\business\control\ArticleController();
	    $articleList = $articleController->getArticleByIds($arrAids);
	    $celebrityInfo = self::getCelebrityInfoByTagIds($arrTagId);
	    $starUrlArr = self::getStarCenterUrlByTagId($arrTagId);	 
	    $newArticleList = array();
	    foreach ($celebrityInfo as $key=>$val){
	    	if(!empty($arrIds[$val->TagId])){
	    		foreach ($articleList as $articleModel){
	    			if($articleModel->Id == $arrIds[$val->TagId]){
	    				$newArticleList[$key] = $articleModel;
	    			}
	    		}
	    	}
	    }
	    return array($newArticleList,$celebrityInfo,$starUrlArr);
	}
	
	public static function getCelebrityInfoByTagIds($tagIds){
	    $celebrityFilter = new CelebrityFilter();
	    $celebrityImageFilter = new CelebrityImageFilter();
	    $celebrityInfoFilter = new CelebrityInfoFilter();
	    $celebrityFilter->select(array(
	        CelebrityFilter::CONDITION_FIELD_NAME_BIRTHDAY,
	        CelebrityFilter::CONDITION_FIELD_NAME_ID,
	        CelebrityFilter::CONDITION_FIELD_NAME_NAME_CN,
	        CelebrityFilter::CONDITION_FIELD_NAME_NAME_EN,
	        CelebrityFilter::CONDITION_FIELD_NAME_TAG_ID
	    ));
	    $celebrityInfoFilter->select(array(
	        CelebrityInfoFilter::CONDITION_FIELD_NAME_XING_ZUO,
	    ));
	    $celebrityRiseFilter = new CelebrityRiseCountFilter();
	    $celebrityRiseFilter->select(array(
	        CelebrityRiseCountFilter::CONDITION_FIELD_NAME_FANS_COUNT
	    ));
	    $imageLibraryFilter = new ImageLibraryFilter();
	    $imageLibraryFilter->select(array(
	        ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
	    ));
	    $celebrityFilter->leftJoin($celebrityInfoFilter,null,CelebrityFilter::CONDITION_FIELD_NAME_ID,CelebrityInfoFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,CelebrityFilter::CONDITION_FIELD_NAME_CELEBRITYINFO,false);
	    $celebrityFilter->leftJoin($celebrityRiseFilter,null,CelebrityFilter::CONDITION_FIELD_NAME_ID,CelebrityRiseCountFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,CelebrityFilter::CONDITION_FIELD_NAME_CELEBRITY_RISECOUNT,false);
	    $celebrityFilter->leftJoin($celebrityImageFilter,null,CelebrityFilter::CONDITION_FIELD_NAME_ID,CelebrityImageFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,CelebrityFilter::CONDITION_FIELD_NAME_CELEBRITY_IMAGE,false);
	    $celebrityFilter->leftJoin($imageLibraryFilter,$celebrityImageFilter,CelebrityImageFilter::CONDITION_FIELD_NAME_IMAGE_ID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,CelebrityImageFilter::CONDITION_FIELD_NAME_IMAGE_Url,false);
	    $celebrityImageFilter->where(CelebrityImageFilter::CONDITION_FIELD_NAME_IMAGE_TYPE, Condition::CONDITION_EQUAL, \haibao\cms\model\data\CelebrityImage::IMAGE_TYPE_PICTURE);
	    $celebrityFilter->where(CelebrityFilter::CONDITION_FIELD_NAME_TAG_ID, Condition::CONDITION_IN, $tagIds);
	    $data = new \haibao\cms\data\ImageLibrary();
	    $celebrity = $data->getAll($celebrityFilter);
	    return $celebrity;
	}
	
	/**
	 * 根据标签获取图集信息
	 * @param : Int $tagId 主标签
	 */
	public static function getImageCollectiveByTagId($tagId,$articleId = 0,$proLevel = 1,$isRemoveArticle = false){

		$imageCollectiveFilter = new ImageCollectiveFilter();
		$imageCollectiveFilter->select(array(
				ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,
				ImageCollectiveFilter::CONDITION_FIELD_NAME_TITLE
				
		));
		
		$imageCollectiveTagFilter = new ImageCollectiveTagFilter();
		$imageCollectiveTagFilter->select(array(
				ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_ID,
				ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_PARENTID
		));
		$imageCollectiveProFilter = new ImageCollectiveProFilter();
		$imageCollectiveProFilter->select(array(
				
		));
		$imageLibraryFilter = new ImageLibraryFilter();
		$imageLibraryFilter->select(array(
				ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME,
		));
		$imageCollectiveFilter->limit(0,4);
		$imageCollectiveFilter->order(ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PUBLISHTIME,false);
		if($isRemoveArticle){
			$imageCollArticleFilter = new ImageCollArticleFilter();
			$imageCollArticleFilter->where(ImageCollArticleFilter::CONDITION_FIELD_NAME_ARITCLE_ID,Condition::CONDITION_NOTEQUAL,$articleId);
			$imageCollectiveFilter->leftjoin($imageCollArticleFilter,null,ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,ImageCollArticleFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID);
		}
		
		$imageCollectiveFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollective::STATUS_ENABLE);
		$imageCollectiveFilter->where(ImageCollectiveFilter::CONDITION_FIELD_NAME_LEVEL,Condition::CONDITION_GREATEREQUAL,6);
		$imageCollectiveTagFilter->where(ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_ISPRIMAIY,Condition::CONDITION_EQUAL,\haibao\cms\model\data\imagecollective\ImageCollectiveTag::IS_PRIMAIY);
		$imageCollectiveTagFilter->where(ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,$tagId);
		$imageCollectiveProFilter->where(ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_IMAGE_TYPE,Condition::CONDITION_IN,array($proLevel,0));
		
		
		$imageCollectiveFilter->leftJoin($imageCollectiveTagFilter,null,ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,ImageCollectiveTagFilter::CONDITION_FIELD_NAME_TAG_COLLECTIVE_ID,ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_TAG,false);
		
		$imageCollectiveFilter->leftJoin($imageCollectiveProFilter,null,ImageCollectiveFilter::CONDITION_FIELD_NAME_ID,ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_ID,ImageCollectiveFilter::CONDITION_FIELD_NAME_IMAGE_COLLECTIVE_PRO,true);
		
		$imageCollectiveFilter->leftJoin($imageLibraryFilter,$imageCollectiveProFilter,ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_ID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,ImageCollectiveProFilter::CONDITION_FIELD_NAME_IMAGE_FILENAME,false);
		
		$data = new \haibao\cms\data\imagecollective\ImageCollective();
		$imageCollective = $data->getAll($imageCollectiveFilter);
		return $imageCollective;
	}
	
	public static function getImagesByArticleId($articleId,$picLevel,$type){
		$data = new \haibao\cms\data\Article();
		return $data->getFocusImageListByArticleId($articleId, $picLevel,$type);
	}
	
	
	public static function queryDB($sql,$param){
		
	}
	
	/**
	 * 获取一条最新的造型日历
	 */
	public static function getNewCalendarInfo(){
		
		$calendarFilter = new CalendarFilter();
		$calendarPicPointFilter = new CalendarPicPointFilter();
		$calendarProductFilter = new CalendarProductFilter();
		$articleFitler = new ArticleFilter();
// 		$articleProImageFilter = new \haibao\www\model\filter\ArticleProImage();
		$articleFitler->select(
				array(
						ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_PUBLISHID,
						ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME
						
		));
		$calendarFilter->select(
				array(
					CalendarFilter::CONDITION_FIELD_NAME_ID,
					CalendarFilter::CONDITION_FIELD_NAME_ARTICLEID,
					CalendarFilter::CONDITION_FIELD_NAME_TITLE,
					CalendarFilter::CONDITION_FIELD_NAME_HOTIMAGEID,
					CalendarFilter::CONDITION_FIELD_NAME_CALENDAR_REL_CREATETIME,
				)
		);
		$calendarPicPointFilter->select(array(
			CalendarPicPointFilter::CONDITION_FIELD_NAME_TITLE,
		));	
// 		$articleProImageFilter->select(array(
// 			\haibao\www\model\filter\ArticleProImage::CONDITION_FIELD_NAME_PIC_URL
// 		));
		$calendarFilter->limit(0,1);
		$calendarFilter->order(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,false,$articleFitler);
		
		
		$calendarFilter->leftJoin($calendarPicPointFilter,null,CalendarFilter::CONDITION_FIELD_NAME_ID,CalendarPicPointFilter::CONDITION_FIELD_NAME_CALENDAR_ID,CalendarFilter::CONDITION_FIELD_NAME_CALENDAR_PIC_POINT,false);
		$calendarFilter->leftJoin($articleFitler,null,CalendarFilter::CONDITION_FIELD_NAME_ARTICLEID,ArticleFilter::CONDITION_FIELD_NAME_ID,CalendarFilter::CONDITION_FIELD_NAME_ARTICLE_INFO,false);
// 		$calendarFilter->leftJoin($articleProImageFilter, null, \haibao\www\model\filter\ArticleProImage::CONDITION_FIELD_NAME_ARTICLE_ID, CalendarFilter::CONDITION_FIELD_NAME_ARTICLEID, CalendarFilter::CONDITION_FIELD_NAME_PIC_INFO, false);
		//$calendarFilter->leftJoin($calendarProductFilter,null,CalendarFilter::CONDITION_FIELD_NAME_ID,CalendarProductFilter::CONDITION_FIELD_NAME_CALENDAR_ID,CalendarFilter::CONDITION_FIELD_NAME_CALENDAR_PRODUCT);
		$articleFitler->where(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHED, Condition::CONDITION_EQUAL, \haibao\cms\model\data\Article::PUBLISHED_YES);
// 		$articleProImageFilter->where(\haibao\cms\model\filter\ArticleProImage::CONDITION_FIELD_NAME_LEVEL, Condition::CONDITION_EQUAL,\haibao\cms\model\data\ArticleProImage::Level_ZERO);
		
		$data = new PublicControllerData();
		$calendar = $data->queryFilter($calendarFilter);

		if($calendar->HotImageId){
			$imageInfo = self::getImageListById($calendar->HotImageId);
			$calendar->HotImageUrl = \haibao\cms\web\common\PublishArticle::getImageRealUrl($imageInfo->Filename, 300, 450);
		}

		$calendar->CalendarProduct = self::getProductByCalendarId($calendar->Id);
		$calendar->CalendarMonth = $calendar->ArticleInfo->PublishTime->Format('M');
		$calendar->CalendarDay = $calendar->ArticleInfo->PublishTime->Format('d');
		$calendar->ArticleUrl = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_CALENDAR).\haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::NEW_ARTICLE_VIEW_NAME).$calendar->ArticleInfo->PublishId.'.htm';
		return $calendar;
	}
	
	/**
	 * 随即获取几天单品数据
	 * @param : $limit 随即条数
	 */
	public static function getRandProductList($limit){
		
		$productFilter = new ProductFilter();
		$productModelFilter = new ProductModelFilter();
		$productFilter->select(array(
			ProductFilter::CONDITION_FIELD_NAME_ID,
			ProductFilter::CONDITION_FIELD_NAME_PRODUCT_NAME,
		));
		$productFilter->limit(0,$limit);
		$productFilter->order(ProductFilter::CONDITION_FIELD_NAME_ID,false);
		$productFilter->where(ProductFilter::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\Product::STATUS_ENABLE);

		$data = new PublicControllerData();
		$products = $data->queryFilter($productFilter,false);
		$productIdArr = array();
		foreach($products as $product){
			array_push($productIdArr,$product->Id);	
		}

		$productModelFilter->select(array(
				ProductModelFilter::CONDITION_FIELD_NAME_PIC_ID,
				ProductModelFilter::CONDITION_FIELD_NAME_PRODUCT_ID,
		));
		$productModelFilter->where(ProductModelFilter::CONDITION_FIELD_NAME_PRODUCT_ID,Condition::CONDITION_IN,$productIdArr);
		
		$productModels = $data->queryFilter($productModelFilter,false);
		
		$productModelArr = $imageIdArr = array();
		if($productModels){
			
			foreach($productModels as $productModel){
				$productModelArr[$productModel->ProductId] = $productModel->PicId;
				array_push($imageIdArr,$productModel->PicId);
				/* if(isset($productModelArr[$productModel->ProductId])){
					array_push($productModelArr[$productModel->ProductId],$productModel->PicId);
				}else{
					$productModelArr[$productModel->ProductId] = array();
					array_push($productModelArr[$productModel->ProductId],$productModel->PicId);
				}*/
			}
			$imageInfo = self::getImageListById($imageIdArr,false);

			foreach($products as $product){
					
				if(isset($productModelArr[$product->Id])){
					$product->ImageUrl = $imageInfo[$productModelArr[$product->Id]];
				}
			}
		}
		return $products;
	}
		
	
	
	/**
	 * 按造型日历找单品数据
	 * @param : $productId 单品id
	 */
	public static function getProductByCalendarId($CalendarId){
		$result = array();
		$productModelFilter = new ProductModelFilter();
		$calendarProductFilter = new CalendarProductFilter();
		$calendarProductFilter->select(array(
				CalendarProductFilter::CONDITION_FIELD_NAME_PRODUCT_ID,
				CalendarProductFilter::CONDITION_FIELD_NAME_ID,
		));
		$productModelFilter->select(array(
				$productModelFilter::CONDITION_FIELD_NAME_ID,
				$productModelFilter::CONDITION_FIELD_NAME_PRODUCT_NAME,
				$productModelFilter::CONDITION_FIELD_NAME_PIC_ID,
				$productModelFilter::CONDITION_FIELD_NAEM_PUBLISHID
		));
		$calendarProductFilter->leftJoin($productModelFilter,null,CalendarProductFilter::CONDITION_FIELD_NAME_PRODUCT_ID,$productModelFilter::CONDITION_FIELD_NAEM_PUBLISHID,CalendarProductFilter::CONDITION_FIELD_NAME_PRODUCTDATA);
		$calendarProductFilter->where(CalendarProductFilter::CONDITION_FIELD_NAME_CALENDAR_ID, Condition::CONDITION_EQUAL, $CalendarId,false);
		$calendarProductFilter->limit(0,4);
		$data = new \haibao\cms\data\Calendar();
		$result = $data->getAll($calendarProductFilter);

		$productModelArr = array();
		$imageIdArr = array();
		$productInfo = array();
		if($result){
			foreach($result as $productModel){
				$productModelArr[$productModel->ProductData[0]->PicId] = $productModel->ProductData[0]->PicId;
				array_push($imageIdArr,$productModel->ProductData[0]->PicId);			
			}
			$imageInfo = self::getImageListById($imageIdArr,false);
			foreach($result as $key => $value){
				if($value->ProductData[0]->ProductName){
					$productInfo[$key]['title'] =  $value->ProductData[0]->ProductName;
				}else{
					$productInfo[$key]['title'] = "";
				}	
						
				$productInfo[$key]['url'] =  \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BRANDS).'/product/'.$value->ProductId;
				if(array_key_exists($value->ProductData[0]->PicId, $imageInfo)){
					$productInfo[$key]['img'] = $imageInfo[$value->ProductData[0]->PicId];
				}else{
					$productInfo[$key]['img'] ="";
				}
			}
		}
		return $productInfo;
	}
	
	
	public static function getImageListById($imageId,$isOne = true){

		$data = new PublicControllerData();
		$imageLibraryFilter = new ImageLibraryFilter();
		$imageLibraryFilter->select(array(
				ImageLibraryFilter::CONDITION_FIELD_NAME_ID,
				ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME
				
		));
		
		if(is_array($imageId)){
			$imageLibraryFilter->where(ImageLibraryFilter::CONDITION_FIELD_NAME_ID,Condition::CONDITION_IN,$imageId);
			
			$imageList = $data->queryFilter($imageLibraryFilter,false);
			$imageInfo = array();
			if($imageList){
				foreach($imageList as $list){
					$imageInfo[$list->Id] = $list->Filename;
				}
				foreach($imageId as $image){
					if(!isset($imageInfo[$image])) $imageInfo[$image] = '';
				}
			}
		}else{
			$imageLibraryFilter->limit(0,1);
			$imageLibraryFilter->where(ImageLibraryFilter::CONDITION_FIELD_NAME_ID,Condition::CONDITION_EQUAL,$imageId);
			$imageInfo = $data->queryFilter($imageLibraryFilter);
		}
		return $imageInfo;

	}
	
	/**
	 * 获取免费使用
	 */
	public static function getTryProduct($limit = 3){
		$tryProductFilter = new \haibao\cms\model\filter\TryProduct();
		$tryProductFilter->select(
				array(
						TryProductFilter::CONDITION_FIELD_NAME_ID,
						TryProductFilter::CONDITION_FIELD_NAME_TITLE,
						TryProductFilter::CONDITION_FIELD_NAME_AMOUNT,
						TryProductFilter::CONDITION_FIELD_NAME_APPLY_END_TIME,
				)
		);
		
		$imageLibraryFilter = new ImageLibraryFilter();
		$imageLibraryFilter->select(
				array(
						ImageLibraryFilter::CONDITION_FIELD_NAME_FILENAME
				)
		);
		
		$tryProductFilter->limit(0,$limit);
		$tryProductFilter->order(TryProductFilter::CONDITION_FIELD_NAME_PUBLISHDATE,false);
		$tryProductFilter->order(TryProductFilter::CONDITION_FIELD_NAME_ID,false);
		
	 	$tryProductFilter->where(TryProductFilter::CONDITION_FIELD_NAME_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\TryProduct::PUBLISHED_YES);
	 	$tryProductFilter->where(TryProductFilter::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\TryProduct::STATUS_ENABLE);
	 	
		$tryProductFilter->where(TryProductFilter::CONDITION_FIELD_NAME_APPLY_START_TIME,Condition::CONDITION_LESSEQUAL,new \DateTime());
		$tryProductFilter->where(TryProductFilter::CONDITION_FIELD_NAME_APPLY_END_TIME,Condition::CONDITION_GREATEREQUAL,new \DateTime());
		$tryProductFilter->leftJoin($imageLibraryFilter,null,TryProductFilter::CONDITION_FIELD_NAME_PIC_ID,ImageLibraryFilter::CONDITION_FIELD_NAME_ID,TryProductFilter::CONDITION_FIELD_NAME_PIC_URL,false);
		
		$tryProducts = \haibao\cms\business\TryProduct::getTryProductByQuery($tryProductFilter);
		if($tryProducts){
			foreach($tryProducts as $key=>$tryProduct){
		
				$applyEndTime = $tryProduct->ApplyEndTime->format('d');
				
				$tryProduct->ApplyEndTime = self::diffTime(date('Y-m-d H:i:s'), $tryProduct->ApplyEndTime->format('Y-m-d H:i:s')) + 1;
			}
		}

		return $tryProducts;
	}
	
	/**
	 * 根据标签ID获取资讯的主标签
	 * 该板块下属资讯流量最高的前5篇的主标签
	 * @param : Array $tagId
	 * @param : Int $limit
	 */
	public static function getArticlePrimaryTagByTagId($tagId,$limit = 5){
		
		if(!$tagId) return false;

		$tagArr = array();
		$data = new PublicControllerData;
		$primaryIdArr = $data->getArticlePrimaryTagByTagId($tagId,$limit = 5);
		if($primaryIdArr){
			$primaryIdArr = array_flip(array_flip($primaryIdArr));
			
			$tagInfo = TagBusiness::getTagsById($primaryIdArr);
			$topTags = \haibao\cms\business\control\Base::getTopTags();
			
			foreach($tagInfo as $key=>$info){
				$info['Url'] = \haibao\cms\business\control\Base::getTagUrl($info['Url'],$info['TagType'],$info['TopId'],$info['Id']);
				array_push($tagArr,$info);
			}
		}
		return $tagArr;
	}
	
	/**
	 * 获取博主最新推荐
	 * @param : $limit 条数
	 */
	public static function getBloggerRecommand($limit = 4,$notin=array()){
		
		$publicControllerData = new PublicControllerData();
		return $publicControllerData->getBloggerRecommand($limit,$notin);
	}
	/**
	 * 根据博主id获取推荐信息
	 */
	public static function getBloggerRecommandByIds($ids){
		$publicControllerData = new PublicControllerData();
		return $publicControllerData->getBloggerRecommandByIds($ids);
	}
	
	/**
	 * 根据博主ID获取博主最新发布的资讯
	 * @param : Array $uid 博主ID 
	 */
	public static function getBlogsByUid($uid){
		
		$uid = (array)$uid;
		$publicControllerData = new PublicControllerData();
		return $publicControllerData->getBlogsByUid($uid);
	}
	
	/**
	 * 获取博主最新更新资讯
	 */
	public static function getNewBlogList($currentPage,$limit = 6){

		$publicControllerData = new PublicControllerData();
		return $publicControllerData->getNewBlogList($currentPage,$limit);
	}
	
	/**
	 * 获取博主最新更新资讯
	 */
	public static function getBlogListByFilter($filter){

		$publicControllerData = new PublicControllerData();
		$publicControllerData->initBlogDB();
		return $publicControllerData->getAll($filter);
	}
	
	/**
	 * 根据博主资讯ID获取资讯导读图
	 */
	public static function getBlogPic($blogIds){

		$publicControllerData = new PublicControllerData();
		$publicControllerData->initBlogDB();
		return $publicControllerData->getBlogPic($blogIds);
	}
	/**
	 * 获取时间范围内点击量最高的博主资讯
	 */
	public static function getBlogByClick($dateType,$limit = 10){

		$publicControllerData = new PublicControllerData();
		return $publicControllerData->getBlogByClick($dateType,$limit);
	}
	
	/**
	 * 获取文章第一张图片
	 */
	public static function getArticleFirstImage($articleId){

		$articleImageFilter = new \haibao\cms\model\filter\ArticleImage();
		$articleImageFilter->select(array(
				\haibao\cms\model\filter\ArticleImage::CONDITION_FIELD_NAME_PIC_URL
		));

		$articleImageFilter->limit(0,1);
		$articleImageFilter->order(\haibao\cms\model\filter\ArticleImage::CONDITION_FIELD_NAME_ID);
		$articleImageFilter->where(\haibao\cms\model\filter\ArticleImage::CONDITION_FIELD_NAME_ARTICLE_ID,Condition::CONDITION_EQUAL,$articleId);
		$data = new \haibao\cms\data\Article();
		$articleImage = $data->getOne($articleImageFilter);
		$imageUrl = '';
		if($articleImage) $imageUrl = $articleImage->PicUrl;
		return $imageUrl;
	}
	
	/**
	 * 截取字符串 超过使用...
	 */
	public static function perfectStr($str,$length=12,$suffix=true,$charset="utf-8") {
		$start  = 0;
		if(function_exists("mb_substr")) {
			if(mb_strlen($str, $charset) <= $length) return $str;
			$slice = mb_substr($str, $start, $length, $charset);
		} else {
			$re['utf-8']   = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
			$re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
			$re['gbk']          = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
			$re['big5']          = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
			preg_match_all($re[$charset], $str, $match);
			if(count($match[0]) <= $length) return $str;
			$slice = join("",array_slice($match[0], $start, $length));
		}
		if($suffix) return $slice."…";
		return $slice;
	}
	
	public static function createBrandsShowData(){
		$cacheData = '';
		$eventCategoryId = 83; //重点时装周 事件分类id
		$starDate = '2014-01-01 00:00:00';
		$brandShowInfoList = \haibao\cms\business\Brand::getBrandShowInfo($eventCategoryId, $starDate);
		$brandShowArticles = $showBrands = $brandShow = $arrBrandTagId = $arrShow = $arrBrand = $result = array();
		if($brandShowInfoList){
			foreach ($brandShowInfoList as $key=>$list){
				$brandTagId = $list['BrandTagId'];
				$eventId = $list['Id'];
				$arrBrandTagId[$brandTagId] = $brandTagId;
				$arrShow[$eventId] = $list['EventName'];
				if(isset($showBrands[$eventId])){
					if(!in_array($brandTagId, $showBrands[$eventId])){
						$showBrands[$eventId][] = $brandTagId;
					}
				}else{
					$showBrands[$eventId][] = $brandTagId;
				}
				if(isset($brandShow[$brandTagId])){
					if(!in_array($eventId, $brandShow[$brandTagId])){
						$brandShow[$brandTagId][] = $eventId;
					}
				}else{
					$brandShow[$brandTagId][] = $eventId;
				}
				if(!isset($brandShowArticles[$brandTagId.':'.$eventId])){
					$brandShowArticles[$brandTagId.':'.$eventId] = \haibao\cms\business\control\Base::getArticleUrl($list['PublishId'],$list['ParentId']);
				}
			}
			$brandList = self::getBrandNameByTagId($arrBrandTagId);
			foreach ($brandList as $k=>$val){
				$arrBrand[$val->TagId] = $val->NameCN.'('.$val->NameEN.')';
			}
	
			$result['showBrands'] = $showBrands;
			$result['brandShow'] = $brandShow;
			$result['arrShow'] = $arrShow;
			$result['arrBrand'] = $arrBrand;
			$result['brandShowArticles'] = $brandShowArticles;
			$cacheData = '<?php '.PHP_EOL.'return  ' . var_export($result, true) . ';';
		}
		return $cacheData;
	}
	
	private static function getBrandNameByTagId($arrBrandTagId){
		$brandFilter = new \haibao\cms\model\filter\Brand();
		$brandFilter->select(array(
				\haibao\cms\model\filter\Brand::CONDITION_FIELD_NAME_ID,
				\haibao\cms\model\filter\Brand::CONDITION_FIELD_NAME_TAG_ID,
				\haibao\cms\model\filter\Brand::CONDITION_FIELD_NAME_NAMECN,
				\haibao\cms\model\filter\Brand::CONDITION_FIELD_NAME_NAMEEN,
		));
		$brandFilter->where(\haibao\cms\model\filter\Brand::CONDITION_FIELD_NAME_TAG_ID, Condition::CONDITION_IN, $arrBrandTagId);
		$brandList = \haibao\cms\business\Brand::getBrandByFilter($brandFilter);
		return $brandList;
	}
	

	/**
	 * 计算两个日期相差多少天
	 */
	private static function diffTime($day1, $day2){
		$second1 = strtotime($day1);
		$second2 = strtotime($day2);
	
		if ($second1 < $second2) {
			$tmp = $second2;
			$second2 = $second1;
			$second1 = $tmp;
		}
		return intval(($second1 - $second2) / 86400);
	}
}
